package cn.com.bluemoon.daps.sync.base;

import com.baomidou.mybatisplus.core.enums.IEnum;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

/**
 * 定义对比出来的类型
 * 该类型不参与业务逻辑的调整，若需要调整该类型的业务定义，请参考{@link DevModelCompareResult#action}
 * 的定义，根据业务定义进行调整：drop-> drop | ignore
 *
 * @author Jarod Kong
 * @date 2021-01-16 20:01
 **/
public enum ModifyType implements IEnum<Integer> {
    DROP("删除", 3),
    CREATE("创建", 1),
    ALTER("修改", 2),
    NONE("无变化", 4);

    private final String desc;
    private final Integer rank, code;

    ModifyType(String desc, Integer rank) {
        this.desc = desc;
        this.rank = rank;
        this.code = rank;
    }

    public Integer getRank() {
        return rank;
    }

    public Integer getCode() {
        return code;
    }

    public Tuple2<ModifyType, ModifyLevel> table() {
        return type(ModifyLevel.TABLE);
    }

    public Tuple2<ModifyType, ModifyLevel> field() {
        return type(ModifyLevel.FIELD);
    }

    public Tuple2<ModifyType, ModifyLevel> index() {
        return type(ModifyLevel.INDEX);
    }

    public Tuple2<ModifyType, ModifyLevel> partition() {
        return type(ModifyLevel.PARTITION);
    }

    private Tuple2<ModifyType, ModifyLevel> type(ModifyLevel level) {
        return Tuples.of(this, level);
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 枚举数据库存储值
     */
    @Override
    public Integer getValue() {
        return getCode();
    }

    public enum ModifyLevel implements IEnum<Integer>{
        TABLE("表", 1),
        FIELD("字段", 2),
        INDEX("索引", 3),
        PARTITION("分区", 4);

        private final String desc;
        private final Integer rank, code;

        ModifyLevel(String desc, Integer rank) {
            this.desc = desc;
            this.rank = rank;
            this.code = rank;
        }

        public String getDesc() {
            return desc;
        }

        public Integer getRank() {
            return rank;
        }

        public Integer getCode() {
            return code;
        }

        /**
         * 枚举数据库存储值
         */
        @Override
        public Integer getValue() {
            return getCode();
        }
    }
}